<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../layuimini-2/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuimini-2/css/layuimini.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label 房间号">房间号</label>
        <div class="layui-input-block">
            <input type="text" name="roomNum" lay-verify="required" lay-reqtext="房间号不能为空" placeholder="请输入房间号" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">房间类型</label>
        <div class="layui-input-block">
            <input type="text" name="type" lay-verify="required" lay-reqtext="房间类型不能为空" placeholder="请输入房间类型" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">楼层</label>
        <div class="layui-input-block">
            <input type="text" name="floor" lay-verify="required" lay-reqtext="楼层不能为空" placeholder="请输入楼层" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">面积</label>
        <div class="layui-input-block">
            <input type="text" name="area" lay-verify="required" lay-reqtext="面积不能为空" placeholder="请输入面积" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">房间费用</label>
        <div class="layui-input-block">
            <input type="text" name="money" lay-verify="required" lay-reqtext="房费不能为空" placeholder="请输入房费" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">押金</label>
        <div class="layui-input-block">
            <input type="text" name="deposit" lay-verify="required" lay-reqtext="押金不能为空" placeholder="请输入押金金额" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">入住情况</label>
        <div class="layui-input-block">
            <input type="text" name="occupStatus" lay-verify="required" lay-reqtext="入住情况不能为空" placeholder="请输入入住情况" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">概况</label>
        <div class="layui-input-block">
            <input type="text" name="descc" lay-verify="required" lay-reqtext="房间概况不能为空" placeholder="请输入房间情况" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-pane">
        <label class="layui-form-label">
            <span class="x-red"></span>图片
        </label>
        <div class="layui-input-inline">
            <button type="button" class="layui-btn" id="upload">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <input id="img" type="hidden" name="img" value="">
            <img id="image" src="" alt="图片" width="100px" >
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../../layuimini-2/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form',"layer","jquery","laydate","upload"], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
            laydate= layui.laydate,
            upload = layui.upload;


        // 文件上传
        upload.render({
            elem: '#upload' //绑定元素
            , url: '/upload.do' //上传接口
            , done: function (res) {
                console.log(res.data)
                $("#img").val(res.data.image);
                $("#image").attr("src", res.data.image);
                // console.log("res=>", res);
                if (res.code == 0) {
                    layer.msg("上传成功!")
                }
                form.render();
            }
            , error: function () {
                layer.msg("上传失败!")
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (obj) {

            $.ajax({
                url:"/room/add.do",
                type:"POST",
                data:obj.field,
                success:function (ret) {
                    // console.log("ret ==>",ret.code);
                    if (ret.code == 0) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    } else {
                        layer.msg("添加失败!")
                    }
                },
                error:function (){
                    layer.msg("服务器正忙!")
                }
            })
            return false;
        });
    });
</script>
</body>
</html>